/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TelaPrincipal.java
 *
 * Created on 03/09/2011, 22:00:39
 */
package labcontrole;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.TitledBorder;
import org.apache.commons.math.complex.Complex;
import org.jfree.chart.ChartPanel;

/**
 *
 * @author Victor
 */
public class TelaPrincipal extends javax.swing.JFrame {

    FThread thread;
    String ip;
    int porta;
    int portaEscrita;
    int portaPV;

    /** Creates new form TelaPrincipal */
    public TelaPrincipal() {
        configAparencia(); // Configurar estilo visual
        initComponents();

        setLocationRelativeTo(null);

        thread = new FThread(this);

        porta = 20081;
        portaEscrita = 0;
        portaPV = 0;

        sinalEscritoPanel.add(new ChartPanel(thread.getChartEscrita()));
        sinalLidoPanel.add(new ChartPanel(thread.getChartLeitura()));

    }

    public void setTr(String text) {
        Tr.setText(text);
    }

    public void setTensao(String text) {
        tensaoTextField.setText(text);
    }

    public void setNivelT1(String text) {
        nivelT1TextField.setText(text);
    }

    public void setNivelT2(String text) {
        nivelT2TextField.setText(text);
    }

    public void setTempoAcomod(String text) {
        Ts.setText(text);
    }

    public void setTempoSubida(String text) {
        Tr.setText(text);
    }

    public void setTempoPico(String text) {
        Tp.setText(text);
    }

    public void setOvershoot(String text) {
        Mp.setText(text);
    }

    public void setGanhoK1(Double k1){
        ganhoK1.setText(String.format("%.5f", k1));
    }

    public void setGanhoK21(Double k21){
        ganhoK21.setText(String.format("%.5f", k21));
    }

    public void setGanhoK22(Double k22){
        ganhoK22.setText(String.format("%.5f", k22));
    }

    public boolean isGraficoControle1Selected() {
        return graficoControle1CheckBox.isSelected();
    }

    public boolean isGraficoRefSelected() {
        return graficoRefCheckBox.isSelected();
    }

    public boolean isGraficoNivelT1Selected() {
        return graficoNivelT1CheckBox.isSelected();
    }

    public boolean isGraficoNivelT2Selected() {
        return graficoNivelT2CheckBox.isSelected();
    }

    public boolean isGraficoErroSelected() {
        return graficoErroCheckBox.isSelected();
    }

    private void configAparencia() {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(TelaPrincipal.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(TelaPrincipal.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(TelaPrincipal.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(TelaPrincipal.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        frameConfig = new javax.swing.JFrame();
        jPanel1 = new javax.swing.JPanel();
        configPorta = new javax.swing.JTextField();
        configIp = new javax.swing.JTextField();
        jComboBox4 = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel36 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jLabel34 = new javax.swing.JLabel();
        jComboBox2 = new javax.swing.JComboBox();
        jLabel35 = new javax.swing.JLabel();
        jComboBox3 = new javax.swing.JComboBox();
        confirmarConfig = new javax.swing.JButton();
        buttonGroupModo = new javax.swing.ButtonGroup();
        buttonGroupLeitura = new javax.swing.ButtonGroup();
        buttonGroupPD = new javax.swing.ButtonGroup();
        buttonGroupPI = new javax.swing.ButtonGroup();
        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        buttonGroup3 = new javax.swing.ButtonGroup();
        groupEstados = new javax.swing.ButtonGroup();
        opcoesControleTabbedPane = new javax.swing.JTabbedPane();
        panelModoSimples = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        referenciaSlider = new javax.swing.JSlider();
        KiRadioButton = new javax.swing.JRadioButton();
        TiRadioButton = new javax.swing.JRadioButton();
        TdRadioButton = new javax.swing.JRadioButton();
        jLabel12 = new javax.swing.JLabel();
        Td = new javax.swing.JTextField();
        Kp = new javax.swing.JTextField();
        KdRadioButton = new javax.swing.JRadioButton();
        Kd = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        Ti = new javax.swing.JTextField();
        tipoControladorCombo = new javax.swing.JComboBox();
        Ki = new javax.swing.JTextField();
        configuracaoComboBox = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        panelModoCascata = new javax.swing.JPanel();
        panelModoSimples1 = new javax.swing.JPanel();
        KiRadioButton1 = new javax.swing.JRadioButton();
        TiRadioButton1 = new javax.swing.JRadioButton();
        TdRadioButton1 = new javax.swing.JRadioButton();
        jLabel18 = new javax.swing.JLabel();
        Td1 = new javax.swing.JTextField();
        Kp1 = new javax.swing.JTextField();
        KdRadioButton1 = new javax.swing.JRadioButton();
        Kd1 = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        Ti1 = new javax.swing.JTextField();
        tipoControladorCombo1 = new javax.swing.JComboBox();
        Ki1 = new javax.swing.JTextField();
        panelModoSimples2 = new javax.swing.JPanel();
        KiRadioButton2 = new javax.swing.JRadioButton();
        TiRadioButton2 = new javax.swing.JRadioButton();
        TdRadioButton2 = new javax.swing.JRadioButton();
        jLabel22 = new javax.swing.JLabel();
        Td2 = new javax.swing.JTextField();
        Kp2 = new javax.swing.JTextField();
        KdRadioButton2 = new javax.swing.JRadioButton();
        Kd2 = new javax.swing.JTextField();
        jLabel23 = new javax.swing.JLabel();
        Ti2 = new javax.swing.JTextField();
        tipoControladorCombo2 = new javax.swing.JComboBox();
        Ki2 = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        referenciaSlider1 = new javax.swing.JSlider();
        panelModoEspacoEstados = new javax.swing.JPanel();
        referenciaSliderEstados = new javax.swing.JSlider();
        jLabel24 = new javax.swing.JLabel();
        panelPolos = new javax.swing.JPanel();
        poloR1 = new javax.swing.JTextField();
        poloR2 = new javax.swing.JTextField();
        poloR3 = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jLabel25 = new javax.swing.JLabel();
        jLabel26 = new javax.swing.JLabel();
        poloJ1 = new javax.swing.JTextField();
        poloJ2 = new javax.swing.JTextField();
        poloJ3 = new javax.swing.JTextField();
        jLabel30 = new javax.swing.JLabel();
        jLabel31 = new javax.swing.JLabel();
        jLabel32 = new javax.swing.JLabel();
        jLabel33 = new javax.swing.JLabel();
        calcularGanhos = new javax.swing.JButton();
        panelGanhos = new javax.swing.JPanel();
        ganhoK1 = new javax.swing.JTextField();
        ganhoK21 = new javax.swing.JTextField();
        ganhoK22 = new javax.swing.JTextField();
        jLabel27 = new javax.swing.JLabel();
        jLabel28 = new javax.swing.JLabel();
        jLabel29 = new javax.swing.JLabel();
        radioGanhos = new javax.swing.JRadioButton();
        radioPolos = new javax.swing.JRadioButton();
        panelMalhaAberta = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        sinalMalhaAbertaComboBox = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        amplitudeTextField = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        periodoTextField = new javax.swing.JTextField();
        graficoPanel = new javax.swing.JPanel();
        sinalEscritoPanel = new javax.swing.JPanel();
        sinalLidoPanel = new javax.swing.JPanel();
        panelCheckBoxGraficos = new javax.swing.JPanel();
        graficoControle1CheckBox = new javax.swing.JCheckBox();
        graficoRefCheckBox = new javax.swing.JCheckBox();
        graficoNivelT1CheckBox = new javax.swing.JCheckBox();
        graficoNivelT2CheckBox = new javax.swing.JCheckBox();
        graficoErroCheckBox = new javax.swing.JCheckBox();
        jToolBar1 = new javax.swing.JToolBar();
        conexaoComboBox = new javax.swing.JComboBox();
        buttonConectar = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JToolBar.Separator();
        buttonEsvaziar = new javax.swing.JButton();
        buttonParar = new javax.swing.JButton();
        buttonEnviar = new javax.swing.JButton();
        jSeparator3 = new javax.swing.JToolBar.Separator();
        jLabel13 = new javax.swing.JLabel();
        tensaoTextField = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        nivelT1TextField = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        nivelT2TextField = new javax.swing.JTextField();
        jSeparator4 = new javax.swing.JToolBar.Separator();
        jLabel10 = new javax.swing.JLabel();
        Mp = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        Tr = new javax.swing.JTextField();
        jLabel20 = new javax.swing.JLabel();
        Ts = new javax.swing.JTextField();
        jLabel21 = new javax.swing.JLabel();
        Tp = new javax.swing.JTextField();
        jMenuBar = new javax.swing.JMenuBar();
        menuArquivo = new javax.swing.JMenu();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        menuSair = new javax.swing.JMenuItem();
        jMenu1 = new javax.swing.JMenu();
        opcoesControleCheckBoxMenuItem = new javax.swing.JCheckBoxMenuItem();
        infoMenuItem = new javax.swing.JCheckBoxMenuItem();
        menuConfig = new javax.swing.JMenu();
        menuConfigCon = new javax.swing.JMenuItem();

        frameConfig.getContentPane().setLayout(new java.awt.GridBagLayout());

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Configurar endereço"));

        configPorta.setText("20081");

        configIp.setText("127.0.0.1");

        jComboBox4.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Planta real", "Simulador" }));

        jLabel5.setText("Porta:");

        jLabel6.setText("Endereço IP:");

        jLabel36.setText("Configurar:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel36)
                        .addGap(18, 18, 18)
                        .addComponent(jComboBox4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(jLabel5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(configPorta)
                            .addComponent(configIp, javax.swing.GroupLayout.DEFAULT_SIZE, 104, Short.MAX_VALUE))))
                .addContainerGap(67, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel36)
                    .addComponent(jComboBox4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(configIp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(configPorta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        frameConfig.getContentPane().add(jPanel1, gridBagConstraints);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Configurar canal"));

        jLabel7.setText("Porta de leitura do tanque 1:");

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "0", "1", "2", "3", "4", "5", "6", "7" }));
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        jLabel34.setText("Porta de leitura do tanque 2:");

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "0", "1", "2", "3", "4", "5", "6", "7" }));
        jComboBox2.setSelectedIndex(1);
        jComboBox2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox2ActionPerformed(evt);
            }
        });

        jLabel35.setText("Porta de escrita:");

        jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "0", "1", "2", "3", "4", "5", "6", "7" }));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                            .addComponent(jLabel34)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addComponent(jLabel7)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel35)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel34)
                    .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel35)
                    .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        frameConfig.getContentPane().add(jPanel2, gridBagConstraints);

        confirmarConfig.setIcon(new javax.swing.ImageIcon(getClass().getResource("/labcontrole/accept.png"))); // NOI18N
        confirmarConfig.setText("Salvar");
        confirmarConfig.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
        confirmarConfig.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                confirmarConfigActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        frameConfig.getContentPane().add(confirmarConfig, gridBagConstraints);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Controlador de Tanques");
        setMinimumSize(new java.awt.Dimension(300, 300));

        opcoesControleTabbedPane.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));

        panelModoSimples.setBorder(javax.swing.BorderFactory.createTitledBorder("Controle do tanque 1 (superior)"));

        jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel8.setText("Referência (cm):");

        referenciaSlider.setMaximum(30);
        referenciaSlider.setPaintLabels(true);
        referenciaSlider.setPaintTicks(true);
        referenciaSlider.setValue(0);
        referenciaSlider.setName("aeee"); // NOI18N
        referenciaSlider.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                referenciaSliderStateChanged(evt);
            }
        });

        buttonGroupPI.add(KiRadioButton);
        KiRadioButton.setText("Ki:");
        KiRadioButton.setEnabled(false);

        buttonGroupPI.add(TiRadioButton);
        TiRadioButton.setText("Ti:");
        TiRadioButton.setEnabled(false);

        buttonGroupPD.add(TdRadioButton);
        TdRadioButton.setText("Td:");
        TdRadioButton.setEnabled(false);

        jLabel12.setText("Kp:");

        Td.setText("0");
        Td.setEnabled(false);
        Td.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                TdFocusGained(evt);
            }
        });

        Kp.setText("1");
        Kp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                KpActionPerformed(evt);
            }
        });

        buttonGroupPD.add(KdRadioButton);
        KdRadioButton.setText("Kd:");
        KdRadioButton.setEnabled(false);

        Kd.setText("0");
        Kd.setEnabled(false);
        Kd.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                KdFocusGained(evt);
            }
        });

        jLabel11.setText("Controlador:");

        Ti.setText("0");
        Ti.setEnabled(false);
        Ti.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                TiFocusGained(evt);
            }
        });

        tipoControladorCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "P", "PD", "PI", "PID", "PI-D" }));
        tipoControladorCombo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tipoControladorComboActionPerformed(evt);
            }
        });

        Ki.setText("0");
        Ki.setEnabled(false);
        Ki.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                KiFocusGained(evt);
            }
        });

        configuracaoComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "# 1", "# 2" }));
        configuracaoComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                configuracaoComboBoxActionPerformed(evt);
            }
        });

        jLabel4.setText("Configuração:");

        javax.swing.GroupLayout panelModoSimplesLayout = new javax.swing.GroupLayout(panelModoSimples);
        panelModoSimples.setLayout(panelModoSimplesLayout);
        panelModoSimplesLayout.setHorizontalGroup(
            panelModoSimplesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelModoSimplesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelModoSimplesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(panelModoSimplesLayout.createSequentialGroup()
                        .addComponent(jLabel11)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tipoControladorCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(24, 24, 24)
                        .addComponent(jLabel12)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(Kp, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panelModoSimplesLayout.createSequentialGroup()
                        .addGroup(panelModoSimplesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(panelModoSimplesLayout.createSequentialGroup()
                                .addComponent(KdRadioButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(Kd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(panelModoSimplesLayout.createSequentialGroup()
                                .addComponent(KiRadioButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(Ki, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(59, 59, 59)
                        .addGroup(panelModoSimplesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(panelModoSimplesLayout.createSequentialGroup()
                                .addComponent(TdRadioButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(Td, javax.swing.GroupLayout.DEFAULT_SIZE, 46, Short.MAX_VALUE))
                            .addGroup(panelModoSimplesLayout.createSequentialGroup()
                                .addComponent(TiRadioButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(Ti, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addGap(41, 41, 41)
                .addGroup(panelModoSimplesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8)
                    .addGroup(panelModoSimplesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addGroup(panelModoSimplesLayout.createSequentialGroup()
                            .addComponent(jLabel4)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(configuracaoComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(referenciaSlider, 0, 0, Short.MAX_VALUE)))
                .addContainerGap(681, Short.MAX_VALUE))
        );

        panelModoSimplesLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {KdRadioButton, KiRadioButton});

        panelModoSimplesLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {Kd, Ki, Kp, Td, Ti});

        panelModoSimplesLayout.setVerticalGroup(
            panelModoSimplesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelModoSimplesLayout.createSequentialGroup()
                .addGroup(panelModoSimplesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(panelModoSimplesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel11)
                        .addComponent(tipoControladorCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panelModoSimplesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(Kp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel12)
                        .addComponent(jLabel4)
                        .addComponent(configuracaoComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(28, 28, 28)
                .addGroup(panelModoSimplesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelModoSimplesLayout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(referenciaSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panelModoSimplesLayout.createSequentialGroup()
                        .addGroup(panelModoSimplesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(Kd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(TdRadioButton)
                            .addComponent(Td, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(KdRadioButton))
                        .addGap(18, 18, 18)
                        .addGroup(panelModoSimplesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(Ki, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(KiRadioButton)
                            .addComponent(TiRadioButton)
                            .addComponent(Ti, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        opcoesControleTabbedPane.addTab("Controle simples", panelModoSimples);

        panelModoCascata.setLayout(new java.awt.GridLayout(1, 0));

        panelModoSimples1.setBorder(javax.swing.BorderFactory.createTitledBorder("Controle do tanque 1 (superior)"));

        buttonGroupPI.add(KiRadioButton1);
        KiRadioButton1.setText("Ki:");
        KiRadioButton1.setEnabled(false);

        buttonGroupPI.add(TiRadioButton1);
        TiRadioButton1.setText("Ti:");
        TiRadioButton1.setEnabled(false);

        buttonGroupPD.add(TdRadioButton1);
        TdRadioButton1.setText("Td:");
        TdRadioButton1.setEnabled(false);

        jLabel18.setText("Kp:");

        Td1.setText("0");
        Td1.setEnabled(false);
        Td1.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                Td1FocusGained(evt);
            }
        });

        Kp1.setText("1");
        Kp1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Kp1ActionPerformed(evt);
            }
        });

        buttonGroupPD.add(KdRadioButton1);
        KdRadioButton1.setText("Kd:");
        KdRadioButton1.setEnabled(false);

        Kd1.setText("0");
        Kd1.setEnabled(false);
        Kd1.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                Kd1FocusGained(evt);
            }
        });

        jLabel19.setText("Controlador:");

        Ti1.setText("0");
        Ti1.setEnabled(false);
        Ti1.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                Ti1FocusGained(evt);
            }
        });

        tipoControladorCombo1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "P", "PD", "PI", "PID", "PI-D" }));
        tipoControladorCombo1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tipoControladorCombo1ActionPerformed(evt);
            }
        });

        Ki1.setText("0");
        Ki1.setEnabled(false);
        Ki1.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                Ki1FocusGained(evt);
            }
        });

        javax.swing.GroupLayout panelModoSimples1Layout = new javax.swing.GroupLayout(panelModoSimples1);
        panelModoSimples1.setLayout(panelModoSimples1Layout);
        panelModoSimples1Layout.setHorizontalGroup(
            panelModoSimples1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelModoSimples1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelModoSimples1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelModoSimples1Layout.createSequentialGroup()
                        .addGroup(panelModoSimples1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(panelModoSimples1Layout.createSequentialGroup()
                                .addComponent(KdRadioButton1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(Kd1))
                            .addGroup(panelModoSimples1Layout.createSequentialGroup()
                                .addComponent(KiRadioButton1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(Ki1, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(65, 65, 65)
                        .addGroup(panelModoSimples1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(panelModoSimples1Layout.createSequentialGroup()
                                .addComponent(TdRadioButton1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(Td1))
                            .addGroup(panelModoSimples1Layout.createSequentialGroup()
                                .addComponent(TiRadioButton1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(Ti1, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(panelModoSimples1Layout.createSequentialGroup()
                        .addComponent(jLabel19)
                        .addGap(6, 6, 6)
                        .addComponent(tipoControladorCombo1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel18)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(Kp1, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(318, 318, 318))
        );
        panelModoSimples1Layout.setVerticalGroup(
            panelModoSimples1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelModoSimples1Layout.createSequentialGroup()
                .addGroup(panelModoSimples1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel19)
                    .addComponent(Kp1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel18)
                    .addComponent(tipoControladorCombo1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(28, 28, 28)
                .addGroup(panelModoSimples1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Kd1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(KdRadioButton1)
                    .addComponent(Td1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(TdRadioButton1))
                .addGap(18, 18, 18)
                .addGroup(panelModoSimples1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(KiRadioButton1)
                    .addComponent(Ki1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Ti1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(TiRadioButton1))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        panelModoCascata.add(panelModoSimples1);

        panelModoSimples2.setBorder(javax.swing.BorderFactory.createTitledBorder("Controle do tanque 2 (inferior)"));

        buttonGroup3.add(KiRadioButton2);
        KiRadioButton2.setText("Ki:");
        KiRadioButton2.setEnabled(false);

        buttonGroup3.add(TiRadioButton2);
        TiRadioButton2.setText("Ti:");
        TiRadioButton2.setEnabled(false);

        buttonGroup2.add(TdRadioButton2);
        TdRadioButton2.setText("Td:");
        TdRadioButton2.setEnabled(false);

        jLabel22.setText("Kp:");

        Td2.setText("0");
        Td2.setEnabled(false);
        Td2.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                Td2FocusGained(evt);
            }
        });

        Kp2.setText("1");
        Kp2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Kp2ActionPerformed(evt);
            }
        });

        buttonGroup2.add(KdRadioButton2);
        KdRadioButton2.setText("Kd:");
        KdRadioButton2.setEnabled(false);

        Kd2.setText("0");
        Kd2.setEnabled(false);
        Kd2.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                Kd2FocusGained(evt);
            }
        });

        jLabel23.setText("Controlador:");

        Ti2.setText("0");
        Ti2.setEnabled(false);

        tipoControladorCombo2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "P", "PD", "PI", "PID", "PI-D" }));
        tipoControladorCombo2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tipoControladorCombo2ActionPerformed(evt);
            }
        });

        Ki2.setText("0");
        Ki2.setEnabled(false);
        Ki2.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                Ki2FocusGained(evt);
            }
        });

        jLabel16.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel16.setText("Referência (cm):");

        referenciaSlider1.setMaximum(30);
        referenciaSlider1.setPaintLabels(true);
        referenciaSlider1.setPaintTicks(true);
        referenciaSlider1.setValue(0);
        referenciaSlider1.setName("aeee"); // NOI18N
        referenciaSlider1.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                referenciaSlider1StateChanged(evt);
            }
        });

        javax.swing.GroupLayout panelModoSimples2Layout = new javax.swing.GroupLayout(panelModoSimples2);
        panelModoSimples2.setLayout(panelModoSimples2Layout);
        panelModoSimples2Layout.setHorizontalGroup(
            panelModoSimples2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelModoSimples2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelModoSimples2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelModoSimples2Layout.createSequentialGroup()
                        .addComponent(jLabel23)
                        .addGap(6, 6, 6)
                        .addComponent(tipoControladorCombo2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel22)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(Kp2, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panelModoSimples2Layout.createSequentialGroup()
                        .addGroup(panelModoSimples2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(panelModoSimples2Layout.createSequentialGroup()
                                .addComponent(KdRadioButton2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(Kd2))
                            .addGroup(panelModoSimples2Layout.createSequentialGroup()
                                .addComponent(KiRadioButton2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(Ki2, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(65, 65, 65)
                        .addGroup(panelModoSimples2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(panelModoSimples2Layout.createSequentialGroup()
                                .addComponent(TdRadioButton2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(Td2))
                            .addGroup(panelModoSimples2Layout.createSequentialGroup()
                                .addComponent(TiRadioButton2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(Ti2, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(39, 39, 39)
                        .addGroup(panelModoSimples2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(referenciaSlider1, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel16))))
                .addContainerGap(100, Short.MAX_VALUE))
        );
        panelModoSimples2Layout.setVerticalGroup(
            panelModoSimples2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelModoSimples2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                .addGroup(panelModoSimples2Layout.createSequentialGroup()
                    .addComponent(jLabel16)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(referenciaSlider1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(panelModoSimples2Layout.createSequentialGroup()
                    .addGroup(panelModoSimples2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel23)
                        .addComponent(Kp2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel22)
                        .addComponent(tipoControladorCombo2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(28, 28, 28)
                    .addGroup(panelModoSimples2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(Kd2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(KdRadioButton2)
                        .addComponent(Td2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(TdRadioButton2))
                    .addGap(18, 18, 18)
                    .addGroup(panelModoSimples2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(KiRadioButton2)
                        .addComponent(Ki2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(Ti2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(TiRadioButton2))))
        );

        panelModoCascata.add(panelModoSimples2);

        opcoesControleTabbedPane.addTab("Controle em cascata", panelModoCascata);

        panelModoEspacoEstados.setBorder(javax.swing.BorderFactory.createTitledBorder("Controle do tanque 2 (inferior)"));

        referenciaSliderEstados.setMaximum(30);
        referenciaSliderEstados.setPaintLabels(true);
        referenciaSliderEstados.setPaintTicks(true);
        referenciaSliderEstados.setValue(0);
        referenciaSliderEstados.setName("aeee"); // NOI18N

        jLabel24.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel24.setText("Referência (cm):");

        panelPolos.setBorder(javax.swing.BorderFactory.createTitledBorder(" Pólos "));

        poloR1.setText("0.9048");
        poloR1.setEnabled(false);

        poloR2.setText("0.9920");
        poloR2.setEnabled(false);

        poloR3.setText("0.9980");
        poloR3.setEnabled(false);

        jLabel9.setText("P1:");

        jLabel25.setText("P2:");

        jLabel26.setText("P3:");

        poloJ1.setText("0");
        poloJ1.setEnabled(false);

        poloJ2.setText("0");
        poloJ2.setEnabled(false);

        poloJ3.setText("0");
        poloJ3.setEnabled(false);

        jLabel30.setText("(real | im) ?");
        jLabel30.setToolTipText("Insira a parte real no primeiro campo; se houver, insira a parte imaginária no segundo campo");

        jLabel31.setText("|");

        jLabel32.setText("|");

        jLabel33.setText("|");

        calcularGanhos.setText("Calcular ganhos");
        calcularGanhos.setEnabled(false);
        calcularGanhos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                calcularGanhosActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelPolosLayout = new javax.swing.GroupLayout(panelPolos);
        panelPolos.setLayout(panelPolosLayout);
        panelPolosLayout.setHorizontalGroup(
            panelPolosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelPolosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelPolosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel25)
                    .addComponent(jLabel26)
                    .addComponent(jLabel9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelPolosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(poloR1, javax.swing.GroupLayout.DEFAULT_SIZE, 77, Short.MAX_VALUE)
                    .addComponent(poloR2)
                    .addComponent(poloR3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelPolosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel33, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel32, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel31, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelPolosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelPolosLayout.createSequentialGroup()
                        .addComponent(poloJ3, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(calcularGanhos))
                    .addGroup(panelPolosLayout.createSequentialGroup()
                        .addGroup(panelPolosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(poloJ1)
                            .addComponent(poloJ2, javax.swing.GroupLayout.DEFAULT_SIZE, 67, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel30)))
                .addContainerGap(16, Short.MAX_VALUE))
        );
        panelPolosLayout.setVerticalGroup(
            panelPolosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelPolosLayout.createSequentialGroup()
                .addGroup(panelPolosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelPolosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(panelPolosLayout.createSequentialGroup()
                            .addComponent(jLabel32)
                            .addGap(39, 39, 39))
                        .addGroup(panelPolosLayout.createSequentialGroup()
                            .addGroup(panelPolosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel9)
                                .addComponent(poloR1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel31))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(panelPolosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(poloR2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel25))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(panelPolosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(poloR3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel26)
                                .addComponent(jLabel33))))
                    .addGroup(panelPolosLayout.createSequentialGroup()
                        .addGroup(panelPolosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(poloJ1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel30))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(poloJ2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panelPolosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(poloJ3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(calcularGanhos))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        panelGanhos.setBorder(javax.swing.BorderFactory.createTitledBorder(" Ganhos "));

        jLabel27.setText("K1:");

        jLabel28.setText("K21:");

        jLabel29.setText("K22:");

        javax.swing.GroupLayout panelGanhosLayout = new javax.swing.GroupLayout(panelGanhos);
        panelGanhos.setLayout(panelGanhosLayout);
        panelGanhosLayout.setHorizontalGroup(
            panelGanhosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelGanhosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelGanhosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel28)
                    .addComponent(jLabel29)
                    .addComponent(jLabel27))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelGanhosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(ganhoK1, javax.swing.GroupLayout.DEFAULT_SIZE, 79, Short.MAX_VALUE)
                    .addComponent(ganhoK21)
                    .addComponent(ganhoK22))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        panelGanhosLayout.setVerticalGroup(
            panelGanhosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelGanhosLayout.createSequentialGroup()
                .addGroup(panelGanhosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel27)
                    .addComponent(ganhoK1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelGanhosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ganhoK21, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel28))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelGanhosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ganhoK22, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel29))
                .addContainerGap(14, Short.MAX_VALUE))
        );

        groupEstados.add(radioGanhos);
        radioGanhos.setSelected(true);
        radioGanhos.setText("Ganhos");
        radioGanhos.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                radioGanhosFocusGained(evt);
            }
        });

        groupEstados.add(radioPolos);
        radioPolos.setText("Pólos");
        radioPolos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radioPolosActionPerformed(evt);
            }
        });
        radioPolos.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                radioPolosFocusGained(evt);
            }
        });

        javax.swing.GroupLayout panelModoEspacoEstadosLayout = new javax.swing.GroupLayout(panelModoEspacoEstados);
        panelModoEspacoEstados.setLayout(panelModoEspacoEstadosLayout);
        panelModoEspacoEstadosLayout.setHorizontalGroup(
            panelModoEspacoEstadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelModoEspacoEstadosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelModoEspacoEstadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(radioGanhos)
                    .addComponent(radioPolos))
                .addGap(18, 18, 18)
                .addComponent(panelGanhos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelPolos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(34, 34, 34)
                .addGroup(panelModoEspacoEstadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel24)
                    .addComponent(referenciaSliderEstados, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(722, 722, 722))
        );
        panelModoEspacoEstadosLayout.setVerticalGroup(
            panelModoEspacoEstadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelModoEspacoEstadosLayout.createSequentialGroup()
                .addGroup(panelModoEspacoEstadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(panelGanhos, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(panelPolos, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, panelModoEspacoEstadosLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(radioGanhos)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(radioPolos))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, panelModoEspacoEstadosLayout.createSequentialGroup()
                        .addComponent(jLabel24)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(referenciaSliderEstados, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        opcoesControleTabbedPane.addTab("Controle em EE", panelModoEspacoEstados);

        jLabel1.setText("Sinal:");

        sinalMalhaAbertaComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Degrau", "Seno", "Cosseno", "Onda Quadrada", "Dente de Serra", "Aleatório" }));
        sinalMalhaAbertaComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sinalMalhaAbertaComboBoxActionPerformed(evt);
            }
        });

        jLabel2.setText("Amplitude: ");

        amplitudeTextField.setText("1.0");

        jLabel3.setText("Período:");

        periodoTextField.setText("1.0");

        javax.swing.GroupLayout panelMalhaAbertaLayout = new javax.swing.GroupLayout(panelMalhaAberta);
        panelMalhaAberta.setLayout(panelMalhaAbertaLayout);
        panelMalhaAbertaLayout.setHorizontalGroup(
            panelMalhaAbertaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelMalhaAbertaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelMalhaAbertaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelMalhaAbertaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(sinalMalhaAbertaComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(panelMalhaAbertaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(periodoTextField, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(amplitudeTextField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 43, Short.MAX_VALUE)))
                .addContainerGap(937, Short.MAX_VALUE))
        );
        panelMalhaAbertaLayout.setVerticalGroup(
            panelMalhaAbertaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelMalhaAbertaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelMalhaAbertaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(sinalMalhaAbertaComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelMalhaAbertaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(amplitudeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelMalhaAbertaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(periodoTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(40, Short.MAX_VALUE))
        );

        opcoesControleTabbedPane.addTab("Controle manual", panelMalhaAberta);

        graficoPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        graficoPanel.setLayout(new java.awt.GridLayout(2, 0));

        sinalEscritoPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Sinal escrito"));
        sinalEscritoPanel.setLayout(new java.awt.BorderLayout());
        graficoPanel.add(sinalEscritoPanel);

        sinalLidoPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Sinais lidos"));
        sinalLidoPanel.setLayout(new java.awt.BorderLayout());
        graficoPanel.add(sinalLidoPanel);

        panelCheckBoxGraficos.setBorder(javax.swing.BorderFactory.createTitledBorder("Gráficos"));
        panelCheckBoxGraficos.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        graficoControle1CheckBox.setSelected(true);
        graficoControle1CheckBox.setText("Sinal de controle");
        panelCheckBoxGraficos.add(graficoControle1CheckBox);

        graficoRefCheckBox.setSelected(true);
        graficoRefCheckBox.setText("Referência");
        panelCheckBoxGraficos.add(graficoRefCheckBox);

        graficoNivelT1CheckBox.setSelected(true);
        graficoNivelT1CheckBox.setText("Nível T1");
        panelCheckBoxGraficos.add(graficoNivelT1CheckBox);

        graficoNivelT2CheckBox.setSelected(true);
        graficoNivelT2CheckBox.setText("Nível T2");
        panelCheckBoxGraficos.add(graficoNivelT2CheckBox);

        graficoErroCheckBox.setText("Erro");
        panelCheckBoxGraficos.add(graficoErroCheckBox);

        jToolBar1.setRollover(true);

        conexaoComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Planta real", "Simulador" }));
        conexaoComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                conexaoComboBoxActionPerformed(evt);
            }
        });
        jToolBar1.add(conexaoComboBox);

        buttonConectar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/labcontrole/disconnect.png"))); // NOI18N
        buttonConectar.setText("Conectar");
        buttonConectar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonConectarActionPerformed(evt);
            }
        });
        jToolBar1.add(buttonConectar);
        jToolBar1.add(jSeparator2);

        buttonEsvaziar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/labcontrole/cancel.png"))); // NOI18N
        buttonEsvaziar.setText("Esvaziar");
        buttonEsvaziar.setEnabled(false);
        buttonEsvaziar.setFocusable(false);
        buttonEsvaziar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        buttonEsvaziar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonEsvaziar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonEsvaziarActionPerformed(evt);
            }
        });
        jToolBar1.add(buttonEsvaziar);

        buttonParar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/labcontrole/delete.png"))); // NOI18N
        buttonParar.setMnemonic('p');
        buttonParar.setText("Parar");
        buttonParar.setEnabled(false);
        buttonParar.setFocusable(false);
        buttonParar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        buttonParar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonParar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonPararActionPerformed(evt);
            }
        });
        jToolBar1.add(buttonParar);

        buttonEnviar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/labcontrole/accept.png"))); // NOI18N
        buttonEnviar.setMnemonic('r');
        buttonEnviar.setText("Enviar");
        buttonEnviar.setEnabled(false);
        buttonEnviar.setFocusable(false);
        buttonEnviar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        buttonEnviar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonEnviar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonEnviarActionPerformed(evt);
            }
        });
        jToolBar1.add(buttonEnviar);
        jToolBar1.add(jSeparator3);

        jLabel13.setText("Tensão: ");
        jToolBar1.add(jLabel13);

        tensaoTextField.setText("0.00");
        jToolBar1.add(tensaoTextField);

        jLabel14.setText(" Nível T1: ");
        jLabel14.setToolTipText("Nível do tanque 1");
        jToolBar1.add(jLabel14);

        nivelT1TextField.setText("0.00");
        jToolBar1.add(nivelT1TextField);

        jLabel15.setText(" Nível T2: ");
        jLabel15.setToolTipText("Nível do tanque 2");
        jToolBar1.add(jLabel15);

        nivelT2TextField.setText("0.00");
        jToolBar1.add(nivelT2TextField);
        jToolBar1.add(jSeparator4);

        jLabel10.setText("Mp (%): ");
        jLabel10.setToolTipText("Overshoot");
        jToolBar1.add(jLabel10);

        Mp.setText("0.00");
        jToolBar1.add(Mp);

        jLabel17.setText(" Tr (seg.): ");
        jLabel17.setToolTipText("Tempo de subida");
        jToolBar1.add(jLabel17);

        Tr.setText("0.00");
        jToolBar1.add(Tr);

        jLabel20.setText(" Ts (seg): ");
        jLabel20.setToolTipText("Tempo de estabilização");
        jToolBar1.add(jLabel20);

        Ts.setText("0.00");
        jToolBar1.add(Ts);

        jLabel21.setText(" Tp (seg): ");
        jLabel21.setToolTipText("Tempo de pico");
        jToolBar1.add(jLabel21);

        Tp.setText("0.00");
        jToolBar1.add(Tp);

        menuArquivo.setMnemonic('A');
        menuArquivo.setText("Arquivo");
        menuArquivo.add(jSeparator1);

        menuSair.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_W, java.awt.event.InputEvent.CTRL_MASK));
        menuSair.setIcon(new javax.swing.ImageIcon(getClass().getResource("/labcontrole/cross.png"))); // NOI18N
        menuSair.setText("Sair");
        menuSair.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                menuSairMouseClicked(evt);
            }
        });
        menuSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuSairActionPerformed(evt);
            }
        });
        menuArquivo.add(menuSair);

        jMenuBar.add(menuArquivo);

        jMenu1.setText("Exibir");
        jMenu1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenu1ActionPerformed(evt);
            }
        });

        opcoesControleCheckBoxMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_0, java.awt.event.InputEvent.CTRL_MASK));
        opcoesControleCheckBoxMenuItem.setSelected(true);
        opcoesControleCheckBoxMenuItem.setText("Opções de controle");
        opcoesControleCheckBoxMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                opcoesControleCheckBoxMenuItemActionPerformed(evt);
            }
        });
        jMenu1.add(opcoesControleCheckBoxMenuItem);

        infoMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_1, java.awt.event.InputEvent.CTRL_MASK));
        infoMenuItem.setSelected(true);
        infoMenuItem.setText("Opções de exibição de sinais");
        infoMenuItem.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                infoMenuItemStateChanged(evt);
            }
        });
        infoMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                infoMenuItemActionPerformed(evt);
            }
        });
        infoMenuItem.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                infoMenuItemPropertyChange(evt);
            }
        });
        jMenu1.add(infoMenuItem);

        jMenuBar.add(jMenu1);

        menuConfig.setMnemonic('d');
        menuConfig.setText("Avançado");

        menuConfigCon.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.CTRL_MASK));
        menuConfigCon.setIcon(new javax.swing.ImageIcon(getClass().getResource("/labcontrole/wrench.png"))); // NOI18N
        menuConfigCon.setText("Configurações");
        menuConfigCon.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuConfigConActionPerformed(evt);
            }
        });
        menuConfig.add(menuConfigCon);

        jMenuBar.add(menuConfig);

        setJMenuBar(jMenuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(13, 13, 13)
                        .addComponent(opcoesControleTabbedPane, 0, 0, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(panelCheckBoxGraficos, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(graficoPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 1194, Short.MAX_VALUE))
                    .addComponent(jToolBar1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 1206, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(graficoPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 325, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelCheckBoxGraficos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(opcoesControleTabbedPane, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void menuSairMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_menuSairMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_menuSairMouseClicked

    private void setOpConexao(String ip, int porta) {
        this.ip = ip;
        this.porta = porta;
    }

    private void buttonConectarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonConectarActionPerformed
        if (conexaoComboBox.getSelectedItem().toString().equals("Planta real")) {
            ip = "10.13.99.69";
//             ip = "192.168.0.100";
        } else {
            ip = "127.0.0.1";
        }

        if (buttonConectar.getText().equals("Conectar")) {
            try {
                // TODO add your handling code here:
                if (thread.conectar(ip, porta)) {
                    buttonEsvaziar.setEnabled(true);
                    buttonParar.setEnabled(true);
                    buttonEnviar.setEnabled(true);
                    buttonConectar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/labcontrole/connect.png")));
                    buttonConectar.setText("Desconectar");
                }
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(null, "Não foi possível estabelecer conexão com o servidor.\nVerifique o IP e a porta informados.", "Erro", 0);
            }
        } else {
            buttonEsvaziar.setEnabled(false);
            buttonParar.setEnabled(false);
            buttonEnviar.setEnabled(false);
            buttonConectar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/labcontrole/disconnect.png")));
            buttonConectar.setText("Conectar");
            thread.ui.Mp.setText("0.0");
            thread.ui.Tp.setText("0.0");
            thread.ui.Ts.setText("0.0");
            thread.ui.Tr.setText("0.0");
        }
    }//GEN-LAST:event_buttonConectarActionPerformed

    private void menuSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuSairActionPerformed
        this.dispose();
    }//GEN-LAST:event_menuSairActionPerformed

    private void menuConfigConActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuConfigConActionPerformed
        frameConfig.setSize(300, 300);
        frameConfig.setVisible(true);
    }//GEN-LAST:event_menuConfigConActionPerformed

    private void confirmarConfigActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_confirmarConfigActionPerformed
        // TODO add your handling code here:
        setOpConexao(configIp.getText(), Integer.parseInt(configPorta.getText()));
        frameConfig.dispose();
    }//GEN-LAST:event_confirmarConfigActionPerformed

    private void referenciaSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_referenciaSliderStateChanged
}//GEN-LAST:event_referenciaSliderStateChanged

    private void TiFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_TiFocusGained
        TiRadioButton.setSelected(true);
}//GEN-LAST:event_TiFocusGained

    private void KiFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_KiFocusGained
        KiRadioButton.setSelected(true);
}//GEN-LAST:event_KiFocusGained

    private void TdFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_TdFocusGained
        TdRadioButton.setSelected(true);
}//GEN-LAST:event_TdFocusGained

    private void KdFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_KdFocusGained
        KdRadioButton.setSelected(true);
}//GEN-LAST:event_KdFocusGained

    private void KpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_KpActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_KpActionPerformed

    private void tipoControladorComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tipoControladorComboActionPerformed
        // TODO add your handling code here:
        String _tipoControlador = (String) tipoControladorCombo.getSelectedItem();
        if (_tipoControlador.equals("PI")) {
            KiRadioButton.setEnabled(true);
            Ki.setEnabled(true);
            TiRadioButton.setEnabled(true);
            Ti.setEnabled(true);
            KdRadioButton.setEnabled(false);
            Kd.setEnabled(false);
            TdRadioButton.setEnabled(false);
            Td.setEnabled(false);
        } else if (_tipoControlador.equals("PD")) {
            KdRadioButton.setEnabled(true);
            Kd.setEnabled(true);
            TdRadioButton.setEnabled(true);
            Td.setEnabled(true);
            KiRadioButton.setEnabled(false);
            Ki.setEnabled(false);
            TiRadioButton.setEnabled(false);
            Ti.setEnabled(false);
        } else if (_tipoControlador.equals("PID")) {
            KdRadioButton.setEnabled(true);
            Kd.setEnabled(true);
            TdRadioButton.setEnabled(true);
            Td.setEnabled(true);
            KiRadioButton.setEnabled(true);
            Ki.setEnabled(true);
            TiRadioButton.setEnabled(true);
            Ti.setEnabled(true);
        } else if (_tipoControlador.equals("P")) {
            KdRadioButton.setEnabled(false);
            Kd.setEnabled(false);
            TdRadioButton.setEnabled(false);
            Td.setEnabled(false);
            KiRadioButton.setEnabled(false);
            Ki.setEnabled(false);
            TiRadioButton.setEnabled(false);
            Ti.setEnabled(false);
        } else if (_tipoControlador.equals("PI-D")) {
            KdRadioButton.setEnabled(true);
            Kd.setEnabled(true);
            TdRadioButton.setEnabled(true);
            Td.setEnabled(true);
            KiRadioButton.setEnabled(true);
            Ki.setEnabled(true);
            TiRadioButton.setEnabled(true);
            Ti.setEnabled(true);
        }
}//GEN-LAST:event_tipoControladorComboActionPerformed

    private void configuracaoComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_configuracaoComboBoxActionPerformed
        // TODO add your handling code here:
        if (configuracaoComboBox.getSelectedItem().toString().equals("# 1")) {
            panelModoSimples.setBorder(new TitledBorder("Controle do tanque 1 (superior)"));
            portaPV = 0;
        } else if (configuracaoComboBox.getSelectedItem().toString().equals("# 2")) {
            panelModoSimples.setBorder(new TitledBorder("Controle do tanque 2 (inferior)"));
            portaPV = 1;
        }
    }//GEN-LAST:event_configuracaoComboBoxActionPerformed

    private void conexaoComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_conexaoComboBoxActionPerformed
    }//GEN-LAST:event_conexaoComboBoxActionPerformed

    private void infoMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_infoMenuItemActionPerformed
        // TODO add your handling code here:
        if (panelCheckBoxGraficos.isVisible()) {
            panelCheckBoxGraficos.setVisible(false);
        } else {
            panelCheckBoxGraficos.setVisible(true);
        }
    }//GEN-LAST:event_infoMenuItemActionPerformed

    private void jMenu1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenu1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jMenu1ActionPerformed

    private void infoMenuItemPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_infoMenuItemPropertyChange
        // TODO add your handling code here:
    }//GEN-LAST:event_infoMenuItemPropertyChange

    private void infoMenuItemStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_infoMenuItemStateChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_infoMenuItemStateChanged

    private void opcoesControleCheckBoxMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_opcoesControleCheckBoxMenuItemActionPerformed
        // TODO add your handling code here:
        if (opcoesControleTabbedPane.isVisible()) {
            opcoesControleTabbedPane.setVisible(false);
            panelModoSimples.setVisible(false);
            panelModoCascata.setVisible(false);
        } else {
            opcoesControleTabbedPane.setVisible(true);
            panelModoSimples.setVisible(true);
            panelModoCascata.setVisible(true);
        }
    }//GEN-LAST:event_opcoesControleCheckBoxMenuItemActionPerformed

    private void buttonEnviarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonEnviarActionPerformed
        // CONTROLE SIMPLES
        if (opcoesControleTabbedPane.getSelectedIndex() == 0) {

            if (configuracaoComboBox.getSelectedIndex() == 0) {
                thread.setModoMalha("1aordem");
            } else {
                thread.setModoMalha("2aordem");
            }

            thread.setTipoControlador((String) tipoControladorCombo.getSelectedItem());
            thread.setReferencia1(referenciaSlider.getValue());

            thread.setKp(Double.parseDouble(Kp.getText()));
            if (Ki.isEnabled()) {
                thread.setKi(Double.parseDouble(Ki.getText()));
            }
            if (Kd.isEnabled()) {
                thread.setKd(Double.parseDouble(Kd.getText()));
            }

            thread.zerarErro();
        } // CONTROLE EM CASCATA
        else if (opcoesControleTabbedPane.getSelectedIndex() == 1) {
            thread.setModoMalha("cascata");
            String tipoControlador1 = (String) tipoControladorCombo1.getSelectedItem();
            String tipoControlador2 = (String) tipoControladorCombo2.getSelectedItem();
            thread.setTipoControlador(tipoControlador1, tipoControlador2);
            thread.setReferencia2(referenciaSlider1.getValue());

            thread.setKp1(Double.parseDouble(Kp1.getText()));
            thread.setKp2(Double.parseDouble(Kp2.getText()));
            if (Ki1.isEnabled()) {
                thread.setKi1(Double.parseDouble(Ki1.getText()));
            }
            if (Kd1.isEnabled()) {
                thread.setKd1(Double.parseDouble(Kd1.getText()));
            }
            if (Ki2.isEnabled()) {
                thread.setKi2(Double.parseDouble(Ki2.getText()));
            }
            if (Kd2.isEnabled()) {
                thread.setKd2(Double.parseDouble(Kd2.getText()));
            }

            thread.zerarErro();
        } // CONTROLE EM ESPACO DE ESTADOS
        else if (opcoesControleTabbedPane.getSelectedIndex() == 2) {
            thread.setModoMalha("EE");
            if (radioPolos.isSelected()) {
                if (ganhoK1.getText().isEmpty() || ganhoK21.getText().isEmpty() || ganhoK22.getText().isEmpty()){
                    JOptionPane.showMessageDialog(null, "É necessário calcular os ganhos (clique em <Calcular ganhos>).", "Erro", 0);
                    return;
                }
            } else {
                thread.setK1(Double.parseDouble(ganhoK1.getText()));
                thread.setK21(Double.parseDouble(ganhoK21.getText()));
                thread.setK22(Double.parseDouble(ganhoK22.getText()));
            }

            thread.zerarErro();
            thread.setReferencia2(referenciaSliderEstados.getValue());
        } // CONTROLE MANUAL (MALHA ABERTA)
        else if (opcoesControleTabbedPane.getSelectedIndex() == 3) {
            thread.setModoMalha("modoMalhaAberta");

            String tipo = sinalMalhaAbertaComboBox.getSelectedItem().toString();
            double amplitude = Double.parseDouble(amplitudeTextField.getText());
            double periodo = Double.parseDouble(periodoTextField.getText());

            thread.setSinal(tipo, amplitude, periodo);
        }


        
        thread.controlador1.setAchouOvershoot(false);
        //thread.controlador1.setOverShoot(0.0);
        thread.controlador1.setFlagSubida(false);
        thread.controlador2.setAchouOvershoot(false);
        //thread.controlador2.setOverShoot(0.0);
        thread.controlador2.setFlagSubida(false);
        Mp.setText("0.0");
        Ts.setText("0.0");
        Tr.setText("0.0");
        Tp.setText("0.0");
        thread.plot();
    }//GEN-LAST:event_buttonEnviarActionPerformed

    private void buttonPararActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonPararActionPerformed
        // TODO add your handling code here:
        Mp.setText("0.0");
        Ts.setText("0.0");
        Tr.setText("0.0");
        Tp.setText("0.0");
        thread.controlador1.setAchouOvershoot(false);
        thread.controlador1.setOverShoot(0.0);
        thread.controlador1.setTempoDeAcomod(0.0);
        thread.controlador1.setTempoDeSubida(0.0);
        thread.controlador1.setFlagSubida(false);
        thread.controlador1.setReferencia(0.0);
        thread.controlador1.setReferenciaAnterior(0.0);
        
        thread.controlador2.setAchouOvershoot(false);
        thread.controlador2.setOverShoot(0.0);
        thread.controlador2.setTempoDeAcomod(0.0);
        thread.controlador2.setTempoDeSubida(0.0);
        thread.controlador2.setFlagSubida(false);
        thread.controlador2.setReferencia(0.0);
        thread.controlador2.setReferenciaAnterior(0.0);        
        
        thread.parar();
    }//GEN-LAST:event_buttonPararActionPerformed

    private void buttonEsvaziarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonEsvaziarActionPerformed
        // TODO add your handling code here:
        thread.esvaziar();
    }//GEN-LAST:event_buttonEsvaziarActionPerformed

    private void Td1FocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_Td1FocusGained
        // TODO add your handling code here:
    }//GEN-LAST:event_Td1FocusGained

    private void Kp1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Kp1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_Kp1ActionPerformed

    private void Kd1FocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_Kd1FocusGained
        // TODO add your handling code here:
    }//GEN-LAST:event_Kd1FocusGained

    private void Ti1FocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_Ti1FocusGained
        // TODO add your handling code here:
    }//GEN-LAST:event_Ti1FocusGained

    private void tipoControladorCombo1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tipoControladorCombo1ActionPerformed
        // TODO add your handling code here:
        String _tipoControlador = (String) tipoControladorCombo1.getSelectedItem();
        if (_tipoControlador.equals("PI")) {
            KiRadioButton1.setEnabled(true);
            Ki1.setEnabled(true);
            TiRadioButton1.setEnabled(true);
            Ti1.setEnabled(true);
            KdRadioButton1.setEnabled(false);
            Kd1.setEnabled(false);
            TdRadioButton1.setEnabled(false);
            Td1.setEnabled(false);
        } else if (_tipoControlador.equals("PD")) {
            KdRadioButton1.setEnabled(true);
            Kd1.setEnabled(true);
            TdRadioButton1.setEnabled(true);
            Td1.setEnabled(true);
            KiRadioButton1.setEnabled(false);
            Ki1.setEnabled(false);
            TiRadioButton1.setEnabled(false);
            Ti1.setEnabled(false);
        } else if (_tipoControlador.equals("PID")) {
            KdRadioButton1.setEnabled(true);
            Kd1.setEnabled(true);
            TdRadioButton1.setEnabled(true);
            Td1.setEnabled(true);
            KiRadioButton1.setEnabled(true);
            Ki1.setEnabled(true);
            TiRadioButton1.setEnabled(true);
            Ti1.setEnabled(true);
        } else if (_tipoControlador.equals("P")) {
            KdRadioButton1.setEnabled(false);
            Kd1.setEnabled(false);
            TdRadioButton1.setEnabled(false);
            Td1.setEnabled(false);
            KiRadioButton1.setEnabled(false);
            Ki1.setEnabled(false);
            TiRadioButton1.setEnabled(false);
            Ti1.setEnabled(false);
        }
    }//GEN-LAST:event_tipoControladorCombo1ActionPerformed

    private void Ki1FocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_Ki1FocusGained
        // TODO add your handling code here:
    }//GEN-LAST:event_Ki1FocusGained

    private void Td2FocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_Td2FocusGained
        // TODO add your handling code here:
    }//GEN-LAST:event_Td2FocusGained

    private void Kp2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Kp2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_Kp2ActionPerformed

    private void Kd2FocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_Kd2FocusGained
        // TODO add your handling code here:
    }//GEN-LAST:event_Kd2FocusGained

    private void tipoControladorCombo2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tipoControladorCombo2ActionPerformed
        String _tipoControlador = (String) tipoControladorCombo2.getSelectedItem();
        if (_tipoControlador.equals("PI")) {
            KiRadioButton2.setEnabled(true);
            Ki2.setEnabled(true);
            TiRadioButton2.setEnabled(true);
            Ti2.setEnabled(true);
            KdRadioButton2.setEnabled(false);
            Kd2.setEnabled(false);
            TdRadioButton2.setEnabled(false);
            Td2.setEnabled(false);
        } else if (_tipoControlador.equals("PD")) {
            KdRadioButton2.setEnabled(true);
            Kd2.setEnabled(true);
            TdRadioButton2.setEnabled(true);
            Td2.setEnabled(true);
            KiRadioButton2.setEnabled(false);
            Ki2.setEnabled(false);
            TiRadioButton2.setEnabled(false);
            Ti2.setEnabled(false);
        } else if (_tipoControlador.equals("PID")) {
            KdRadioButton2.setEnabled(true);
            Kd2.setEnabled(true);
            TdRadioButton2.setEnabled(true);
            Td2.setEnabled(true);
            KiRadioButton2.setEnabled(true);
            Ki2.setEnabled(true);
            TiRadioButton2.setEnabled(true);
            Ti2.setEnabled(true);
        } else if (_tipoControlador.equals("P")) {
            KdRadioButton2.setEnabled(false);
            Kd2.setEnabled(false);
            TdRadioButton2.setEnabled(false);
            Td2.setEnabled(false);
            KiRadioButton2.setEnabled(false);
            Ki2.setEnabled(false);
            TiRadioButton2.setEnabled(false);
            Ti2.setEnabled(false);
        }

    }//GEN-LAST:event_tipoControladorCombo2ActionPerformed

    private void Ki2FocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_Ki2FocusGained
        // TODO add your handling code here:
    }//GEN-LAST:event_Ki2FocusGained

    private void referenciaSlider1StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_referenciaSlider1StateChanged
        // TODO add your handling code here:
}//GEN-LAST:event_referenciaSlider1StateChanged

    private void sinalMalhaAbertaComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sinalMalhaAbertaComboBoxActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_sinalMalhaAbertaComboBoxActionPerformed

    private void radioPolosFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_radioPolosFocusGained
        ganhoK1.setEnabled(false);
        ganhoK21.setEnabled(false);
        ganhoK22.setEnabled(false);
        poloR1.setEnabled(true);
        poloR2.setEnabled(true);
        poloR3.setEnabled(true);
        poloJ1.setEnabled(true);
        poloJ2.setEnabled(true);
        poloJ3.setEnabled(true);
        calcularGanhos.setEnabled(true);
    }//GEN-LAST:event_radioPolosFocusGained

    private void radioGanhosFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_radioGanhosFocusGained
        ganhoK1.setEnabled(true);
        ganhoK21.setEnabled(true);
        ganhoK22.setEnabled(true);
        poloR1.setEnabled(false);
        poloR2.setEnabled(false);
        poloR3.setEnabled(false);
        poloJ1.setEnabled(false);
        poloJ2.setEnabled(false);
        poloJ3.setEnabled(false);
        calcularGanhos.setEnabled(false);
    }//GEN-LAST:event_radioGanhosFocusGained

    private void radioPolosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioPolosActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_radioPolosActionPerformed

    private void calcularGanhosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_calcularGanhosActionPerformed
        // TODO add your handling code here:
        Double pR1 = Double.parseDouble(poloR1.getText());
        Double pJ1 = Double.parseDouble(poloJ1.getText());
        Double pR2 = Double.parseDouble(poloR2.getText());
        Double pJ2 = Double.parseDouble(poloJ2.getText());
        Double pR3 = Double.parseDouble(poloR3.getText());
        Double pJ3 = Double.parseDouble(poloJ3.getText());

        thread.setP1(new Complex(pR1, pJ1));
        thread.setP2(new Complex(pR2, pJ2));
        thread.setP3(new Complex(pR3, pJ3));

        thread.calcularGanhos();
    }//GEN-LAST:event_calcularGanhosActionPerformed

    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBox1ActionPerformed

    private void jComboBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBox2ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField Kd;
    private javax.swing.JTextField Kd1;
    private javax.swing.JTextField Kd2;
    private javax.swing.JRadioButton KdRadioButton;
    private javax.swing.JRadioButton KdRadioButton1;
    private javax.swing.JRadioButton KdRadioButton2;
    private javax.swing.JTextField Ki;
    private javax.swing.JTextField Ki1;
    private javax.swing.JTextField Ki2;
    private javax.swing.JRadioButton KiRadioButton;
    private javax.swing.JRadioButton KiRadioButton1;
    private javax.swing.JRadioButton KiRadioButton2;
    private javax.swing.JTextField Kp;
    private javax.swing.JTextField Kp1;
    private javax.swing.JTextField Kp2;
    private javax.swing.JTextField Mp;
    private javax.swing.JTextField Td;
    private javax.swing.JTextField Td1;
    private javax.swing.JTextField Td2;
    private javax.swing.JRadioButton TdRadioButton;
    private javax.swing.JRadioButton TdRadioButton1;
    private javax.swing.JRadioButton TdRadioButton2;
    private javax.swing.JTextField Ti;
    private javax.swing.JTextField Ti1;
    private javax.swing.JTextField Ti2;
    private javax.swing.JRadioButton TiRadioButton;
    private javax.swing.JRadioButton TiRadioButton1;
    private javax.swing.JRadioButton TiRadioButton2;
    private javax.swing.JTextField Tp;
    private javax.swing.JTextField Tr;
    private javax.swing.JTextField Ts;
    private javax.swing.JTextField amplitudeTextField;
    private javax.swing.JButton buttonConectar;
    private javax.swing.JButton buttonEnviar;
    private javax.swing.JButton buttonEsvaziar;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.ButtonGroup buttonGroup3;
    private javax.swing.ButtonGroup buttonGroupLeitura;
    private javax.swing.ButtonGroup buttonGroupModo;
    private javax.swing.ButtonGroup buttonGroupPD;
    private javax.swing.ButtonGroup buttonGroupPI;
    private javax.swing.JButton buttonParar;
    private javax.swing.JButton calcularGanhos;
    private javax.swing.JComboBox conexaoComboBox;
    private javax.swing.JTextField configIp;
    private javax.swing.JTextField configPorta;
    private javax.swing.JComboBox configuracaoComboBox;
    private javax.swing.JButton confirmarConfig;
    private javax.swing.JFrame frameConfig;
    private javax.swing.JTextField ganhoK1;
    private javax.swing.JTextField ganhoK21;
    private javax.swing.JTextField ganhoK22;
    private javax.swing.JCheckBox graficoControle1CheckBox;
    private javax.swing.JCheckBox graficoErroCheckBox;
    private javax.swing.JCheckBox graficoNivelT1CheckBox;
    private javax.swing.JCheckBox graficoNivelT2CheckBox;
    private javax.swing.JPanel graficoPanel;
    private javax.swing.JCheckBox graficoRefCheckBox;
    private javax.swing.ButtonGroup groupEstados;
    private javax.swing.JCheckBoxMenuItem infoMenuItem;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JComboBox jComboBox3;
    private javax.swing.JComboBox jComboBox4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel29;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel31;
    private javax.swing.JLabel jLabel32;
    private javax.swing.JLabel jLabel33;
    private javax.swing.JLabel jLabel34;
    private javax.swing.JLabel jLabel35;
    private javax.swing.JLabel jLabel36;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JToolBar.Separator jSeparator2;
    private javax.swing.JToolBar.Separator jSeparator3;
    private javax.swing.JToolBar.Separator jSeparator4;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JMenu menuArquivo;
    private javax.swing.JMenu menuConfig;
    private javax.swing.JMenuItem menuConfigCon;
    private javax.swing.JMenuItem menuSair;
    private javax.swing.JTextField nivelT1TextField;
    private javax.swing.JTextField nivelT2TextField;
    private javax.swing.JCheckBoxMenuItem opcoesControleCheckBoxMenuItem;
    private javax.swing.JTabbedPane opcoesControleTabbedPane;
    private javax.swing.JPanel panelCheckBoxGraficos;
    private javax.swing.JPanel panelGanhos;
    private javax.swing.JPanel panelMalhaAberta;
    private javax.swing.JPanel panelModoCascata;
    private javax.swing.JPanel panelModoEspacoEstados;
    private javax.swing.JPanel panelModoSimples;
    private javax.swing.JPanel panelModoSimples1;
    private javax.swing.JPanel panelModoSimples2;
    private javax.swing.JPanel panelPolos;
    private javax.swing.JTextField periodoTextField;
    private javax.swing.JTextField poloJ1;
    private javax.swing.JTextField poloJ2;
    private javax.swing.JTextField poloJ3;
    private javax.swing.JTextField poloR1;
    private javax.swing.JTextField poloR2;
    private javax.swing.JTextField poloR3;
    private javax.swing.JRadioButton radioGanhos;
    private javax.swing.JRadioButton radioPolos;
    private javax.swing.JSlider referenciaSlider;
    private javax.swing.JSlider referenciaSlider1;
    private javax.swing.JSlider referenciaSliderEstados;
    private javax.swing.JPanel sinalEscritoPanel;
    private javax.swing.JPanel sinalLidoPanel;
    private javax.swing.JComboBox sinalMalhaAbertaComboBox;
    private javax.swing.JTextField tensaoTextField;
    private javax.swing.JComboBox tipoControladorCombo;
    private javax.swing.JComboBox tipoControladorCombo1;
    private javax.swing.JComboBox tipoControladorCombo2;
    // End of variables declaration//GEN-END:variables
}
